package com.scheuk.euler;

import java.util.BitSet;
/**
 * The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 * Find the sum of all the primes below two million.
 * @author scheuk
 *
 */
public class p010 {

	public static long findPrimeSum(int upperbound)
	{
		BitSet bs = MathTools.computePrimes(upperbound);
		long sum = 0;
		for (int i = 0; i < upperbound; i++)
		{
			sum = (bs.get(i)) ? sum+=i : sum; 
			
		}
		return sum;
	}
	
	public static void main(String[] args)
	{
		//1179908154 isn't correct
		long start = System.currentTimeMillis();
		System.out.println("time: " + ((System.currentTimeMillis() - start)/1000) + " s");
		System.out.println("answer: " + p010.findPrimeSum(2000000));
	}
}
